package com.lanqiao.gxnushop.controller;

import java.util.ArrayList;
import com.lanqiao.gxnushop.entity.Address;
import com.lanqiao.gxnushop.entity.Buyers;
import com.lanqiao.gxnushop.service.AddressService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Log4j
@Tag(name = "AddressContrller",description="地址管理")
@RestController
public class AddressController {
    @Autowired
    private AddressService addressService;

    @PostMapping("/address")
    @Operation(summary="增加地址信息先判断买家Id是否存在")
    @Parameter(name = "address",description = "地址信息:addressId(自动生成),buyerId(不为null),address,phone,name")
    public boolean addAddress(Address address) {
        return addressService.addAddress(address);
    }

    @DeleteMapping("/address/{addressId}")
    @Operation(summary="根据addressId删除对应地址信息")
    @Parameter(name = "addressId",description = "地址id:addressId(不为null)")
    public boolean deleteAddress(@PathVariable String addressId) {
        return addressService.deleteAddress(addressId);
    }

    @GetMapping("/address/{addressId}")
    @Operation(summary="根据地址addressId查询地址信息")
    @Parameter(name = "addressId",description = "地址id:addressId(不为null)")
    public Address findById(@PathVariable String addressId) {
        return addressService.findById(addressId);
    }

    @PutMapping("/address")
    @Operation(summary="根据addressId(不为null)更新地址信息")
    @Parameter(name = "address",description = "addressId(不为null),地址信息:address,phone,name")
    public boolean updateAddress(Address address) {
        return addressService.updateAddress(address);
    }

    @GetMapping("/address")
    @Operation(summary="根据buyerI查询地址信息")
    @Parameter(name = "buyerId",description = "buyerId(不为null),地址信息:address,phone,name")
    public ArrayList<Address> findByUserId(String buyerId) {
        return addressService.findByUserId(buyerId);
    }
}
